import csv
import re
from urllib import request
from urllib import parse
from urllib import error

url = 'file:///D:/%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/python/%E7%88%AC%E8%99%AB/untitled/%E5%89%AF%E6%95%99%E6%8E%88-%E6%95%B0%E5%AD%97%E5%AA%92%E4%BD%93%E4%B8%8E%E8%AE%BE%E8%AE%A1%E8%89%BA%E6%9C%AF%E5%AD%A6%E9%99%A2.html'
res = request.urlopen(url)
f = res.read().decode('utf-8')
# print(f)
m = open("data.csv",mode="w",newline='')
csvwriter = csv.writer(m)
obj = re.compile(r'<img src="(?P<url>.*?)".*?'
 r'<span class="name">(?P<name>.*?)</span>.*?'
                 r'<span class="iden">(?P<iden>.*?)</span>',re.S)
result = obj.finditer(f)
dic1 = dict({1:"Department",2:"Name",3:"Title",4:"Photo"})
csvwriter.writerow(dic1.values())
for it in result:
    dic = it.groupdict()
    dic['url'] = 'file:///D:/学习资料/程序设计/python/爬虫/untitled' + dic['url']
    diclist = list(dic.items())
    diclist.reverse()
    diclist.insert(2,('position','副教授'))
    dic = dict(diclist)
    csvwriter.writerow(dic.values())
m.close()

url = 'file:///D:/%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/python/%E7%88%AC%E8%99%AB/untitled/%E8%AE%B2%E5%B8%88-%E6%95%B0%E5%AD%97%E5%AA%92%E4%BD%93%E4%B8%8E%E8%AE%BE%E8%AE%A1%E8%89%BA%E6%9C%AF%E5%AD%A6%E9%99%A2.htm'
res = request.urlopen(url)
f = res.read().decode('utf-8')
m = open("data.csv",mode="a",newline='')
csvwriter = csv.writer(m)
obj = re.compile(r'<img src="(?P<url>.*?)".*?'
 r'<span class="name">(?P<name>.*?)</span>.*?'
                 r'<span class="iden">(?P<iden>.*?)</span>',re.S)
result = obj.finditer(f)
for it in result:
    dic = it.groupdict()
    dic['url'] = 'file:///D:/学习资料/程序设计/python/爬虫/untitled' + dic['url']
    diclist = list(dic.items())
    diclist.reverse()
    diclist.insert(2,('position','讲师'))
    dic = dict(diclist)
    csvwriter.writerow(dic.values())
m.close()

url = 'file:///D:/%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/python/%E7%88%AC%E8%99%AB/untitled/%E6%95%99%E6%8E%88-%E6%95%B0%E5%AD%97%E5%AA%92%E4%BD%93%E4%B8%8E%E8%AE%BE%E8%AE%A1%E8%89%BA%E6%9C%AF%E5%AD%A6%E9%99%A2.htm'
res = request.urlopen(url)
f = res.read().decode('utf-8')
m = open("data.csv",mode="a",newline='')
csvwriter = csv.writer(m)
obj = re.compile(r'<img src="(?P<url>.*?)".*?'
 r'<span class="name">(?P<name>.*?)</span>.*?'
                 r'<span class="iden">(?P<iden>.*?)</span>',re.S)
result = obj.finditer(f)
for it in result:
    dic = it.groupdict()
    dic['url'] = 'file:///D:/学习资料/程序设计/python/爬虫/untitled' + dic['url']
    diclist = list(dic.items())
    diclist.reverse()
    diclist.insert(2,('position','教授'))
    dic = dict(diclist)
    csvwriter.writerow(dic.values())
m.close()